<template>
	<div class="container">
		<div class="jx-container">
      <div class="select-type">
        <div class="item table-item">
          <div class="right">
            <div class="item-inline">
              <span>产品名称</span>
              <el-input class="tel-value" v-model="params_list.name" placeholder="请输入产品名称"></el-input>
            </div>
            <div class="item-inline">
              <span>店铺名称</span>
              <el-input class="tel-value" v-model="params_list.shopname" placeholder="请输入店铺名称"></el-input>
            </div>
            <div class="item-inline">
              <span>SPU号</span>
              <el-input class="tel-value" v-model="params_list.SPU" placeholder="请输入SPU"></el-input>
            </div>
            <div class="item-inline">
              <span>商品类型</span>
              <el-select class="tel-value" v-model="params_list.type" placeholder="请选择">
                <el-option v-for="(item,index) in typelist" :key="index" :label="item" :value="item"></el-option>
              </el-select>
            </div>
            <div class="item-inline">
              <el-button class="jx-btn" type="primary" @click="search">搜索</el-button>
            </div>
          </div>
        </div>
      </div>
      <div class="jx-table">
        <div class="title">
          <img class="icon" src="/static/img/icon-platform.png"/>
          店铺产品列表
        </div>
        <el-table :data="shoplist" border style="width: 100%" v-loading="boo.loading">
          <el-table-column type="index" label="序列" width="55" align="center">
            <template slot-scope="scope">
              <span>{{(scope.$index + 1) + ((params_list.page - 1) * params_list.size)}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="shopProductImgUrl" label="产品图片" width="130" align="center">
            <template slot-scope="scope">
              <img class="logo" :src="scope.row.shopProductImgUrl"/>
            </template>
          </el-table-column>
          <el-table-column prop="shopProductName" label="产品名称" width="180" align="center" :show-overflow-tooltip="true">
            <template slot-scope="scope">
              <el-button @click="viewRow(scope.row)" type="text" size="small">{{scope.row.shopProductName}}</el-button>
            </template>
          </el-table-column>
          <el-table-column prop="shopProductSPU" label="SPU号" align="center" :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column prop="shopName" label="店铺" align="center" :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column prop="shopLocationProvinceCity" label="所在地区" align="center" :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column prop="shopProductPrice" label="价格" align="center" :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column prop="shopProductInventory" label="库存数量" align="center">
          </el-table-column>
          <el-table-column prop="shopProductCatalog" label="商品类型" align="center" >
          </el-table-column>
          <el-table-column prop="shopProductScore" label="产品综合评分" align="center">
          </el-table-column>
          <el-table-column prop="shopProductStatus" label="状态" align="center">
          </el-table-column>
          <el-table-column label="操作" width="90" align="center">
            <template slot-scope="scope">
              <el-button @click="hiddenRow(scope.row)" type="text" size="small">{{scope.row.shopProductStatus == '上架' ? '下架' : '上架'}}</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div v-if="shoplist.length != 0" class="jx-pagination">
          <el-pagination @current-change="pageChange" @size-change="handleSizeChange" :current-page="params_list.page" :page-sizes="[10,50,100]" :page-size="params_list.size" layout="total, sizes, prev, pager, next, jumper"
            :total="other.allRow">
          </el-pagination>
        </div>
      </div>
    </div>
	</div>
</template>

<script>
	export default {
		data() {
			return {
        https: {
          shop: this.$api.product.shop,
          common: this.$api.common.dict,
        },
        boo: {
          loading: false,
        },
        other: {
          allRow: 1,
        },
        shoplist: '',
        params_list: {
          page: 1,
          size: 10,
          shopname: '',
          type: '',
          name: '',
          SPU: '',
        },
        typelist: '',
			}
		},
		mounted(){
      let _self = this
      _self.getList()
      _self.getDict('shopProductCatalog')
    },
		methods: {
      getDict(type){
        let _self = this
        let params = {
          dictCode: type,
        }
        // 新建判断Map
        let actions = (i,list,)=>{
          return new Map([
            ['shopProductCatalog',()=>{
              _self.typelist = list
            }]
          ]).get(i).call(this)
        }
        let success = (res)=>{
          if(res.data.retCode == 1){
            actions(type,res.data.retObject)
          }else{
            _self.$message.error(res.data.retMsg)
          }
        }
        _self.$axios.get(_self.https.common, params, success) 
      },
      getList(){
        let _self = this
        let params = {
          shopProductName: _self.params_list.name || '',
          shopName: _self.params_list.shopname || '',
          shopProductSPU: _self.params_list.SPU || '',
          shopProductCatalog: _self.params_list.type || '',
          orderBy: '',
          pageNumber: _self.params_list.page,
          pageSize: _self.params_list.size,
        }
        _self.boo.loading = true
        let success = (res)=>{
          res = res.data
          if(res.retCode == 1){
            _self.shoplist = res.retObject.list
            _self.other.allRow = Number(res.retObject.totalRow)
          }else{
            _self.$message.error(res.retMsg)
          }
          _self.boo.loading = false
        }
        _self.$axios.get(_self.https.shop.list, params, success)
      },
      pageChange(val){
        let _self = this
        _self.params_list.page = val
        _self.getList()
      },
      handleSizeChange(val) {
        let _self = this
        _self.params_list.size = val
        _self.getList()
      },
      search(){
        let _self = this
        _self.getList()
      },
      hiddenRow(){
        
      },
      viewRow(item){
        let _self = this
        let params = {
          path: '/product/detail/product_detail?id=',
          query: item.shopProductId
        }
        _self.$router.push(params.path + params.query)
      }
    }
	}

</script>
<style scoped lang="sass">
  .select-type .table-item .right span
    width: 62px
  .jx-table
    /deep/ .el-table__body td
      .cell
        height: auto
        line-height: auto
</style>
